<template>
  <view class="error-container">
    <view class="error-content">
      <view class="error-icon">❌</view>
      <view class="error-title">页面不存在</view>
      <view class="error-desc">抱歉，您访问的页面不存在或已被移除</view>
      <view class="error-actions">
        <button class="primary-button" @click="goBack">返回上一页</button>
        <button class="secondary-button" @click="goHome">返回首页</button>
      </view>
    </view>
  </view>
</template>

<script setup>
import { onLoad } from '@dcloudio/uni-app';

// 页面加载时记录日志
onLoad(() => {
  console.log('404页面访问:', getCurrentPages().length > 0 ? getCurrentPages()[getCurrentPages().length - 1].route : 'unknown');
});

// 返回上一页
const goBack = () => {
  if (getCurrentPages().length > 1) {
    uni.navigateBack();
  } else {
    // 如果没有上一页，则返回首页
    goHome();
  }
};

// 返回首页
const goHome = () => {
  uni.switchTab({ url: '/pages/index/index' });
};
</script>

<style scoped lang="less">
.error-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #f8f8f8;
  padding: 40rpx;
}

.error-content {
  text-align: center;
  padding: 60rpx;
  background-color: #fff;
  border-radius: 20rpx;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
  width: 100%;
  max-width: 600rpx;
}

.error-icon {
  font-size: 160rpx;
  margin-bottom: 30rpx;
}

.error-title {
  font-size: 48rpx;
  font-weight: bold;
  color: #333;
  margin-bottom: 20rpx;
}

.error-desc {
  font-size: 32rpx;
  color: #666;
  margin-bottom: 60rpx;
  line-height: 50rpx;
}

.error-actions {
  display: flex;
  gap: 30rpx;
  justify-content: center;
}

.primary-button {
  flex: 1;
  background-color: #007aff;
  color: #fff;
  border: none;
  border-radius: 50rpx;
  padding: 24rpx 0;
  font-size: 32rpx;
}

.secondary-button {
  flex: 1;
  background-color: #f5f5f5;
  color: #333;
  border: 1rpx solid #ddd;
  border-radius: 50rpx;
  padding: 24rpx 0;
  font-size: 32rpx;
}

.primary-button:active {
  opacity: 0.8;
}

.secondary-button:active {
  background-color: #e8e8e8;
}
</style>